﻿using BW.IBLL;
using BW.Model;
using Dto;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace LMLZKOne.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        public UserController(IBaseBLL bll, ILogger<UserController> logger)
        {
            Bll = bll;
            _Logger = logger;
        }

        public IBaseBLL Bll { get; }
        public ILogger<UserController> _Logger { get; }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model">对象</param>
        /// <returns>受影响的行数</returns>
        [HttpPost]
        public async Task<int> tianjia(UserModel model)
        {
            try
            {
                _Logger.LogInformation("新增成功");
                return await Bll.tianjia(model);
            }
            catch (Exception)
            {
                _Logger.LogError("新增失败");
                throw;
            }
             
        }
        /// <summary>
        /// 显示+分页+模糊查询+等值查询
        /// </summary>
        /// <param name="index">总页容量</param>
        /// <param name="size">总数据</param>
        /// <param name="uname">姓名</param>
        /// <param name="tid">职业类型</param>
        /// <returns>受影响的行数</returns>
        [HttpGet]
        public MyDto xisnshi(int index, int size, string? uname, int? tid)
        {
            try
            {
                _Logger.LogInformation("显示成功");
                return Bll.xisnshi(index, size, uname, tid);
            }
            catch (Exception)
            {
                _Logger.LogError("显示失败");
                throw;
            }
             
        }
        /// <summary>
        /// 单个上架下架
        /// </summary>
        /// <param name="id">对象</param>
        /// <returns>受影响的行数</returns>
        [HttpGet]
        public Task<int> UpdateStart(int id)
        {
            try
            {
                _Logger.LogInformation("修改状态成功");
                return Bll.UpdateStart(id);
            }
            catch (Exception)
            {
                _Logger.LogError("修改状态失败");
                throw;
            }
           
        }
        /// <summary>
        /// 绑定
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public List<UserTypeModel> bang()
        {
            try
            {
                _Logger.LogInformation("绑定成功");
                return Bll.bang();
            }
            catch (Exception)
            {
                _Logger.LogError("绑定失败");
                throw;
            }
          
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="employee"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateEmployee(UserModel employee)
        {
             return await Bll.UpdateEmployee(employee);   
        }
        /// <summary>
        /// 返填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public UserModel GetEmployeeById(int id)
        {
            return Bll.GetEmployeeById(id);
        }
    }
}
